/* ---------------------------------------------------------------------- */
/* Script generated with: DeZign for Databases v6.3.4                     */
/* Target DBMS:           MS SQL Server 2005                              */
/* Project file:          Project1.dez                                    */
/* Project name:                                                          */
/* Author:                                                                */
/* Script type:           Database creation script                        */
/* Created on:            2012-01-06 16:11                                */
/* ---------------------------------------------------------------------- */


/* ---------------------------------------------------------------------- */
/* Tables                                                                 */
/* ---------------------------------------------------------------------- */

/* ---------------------------------------------------------------------- */
/* Add table "Roll"                                                       */
/* ---------------------------------------------------------------------- */

CREATE TABLE [Roll] (
    [id] INTEGER IDENTITY(0,1) NOT NULL,
    [name] NVARCHAR(50),
    CONSTRAINT [PK_Roll] PRIMARY KEY ([id])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "menu"                                                       */
/* ---------------------------------------------------------------------- */

CREATE TABLE [menu] (
    [id] INTEGER IDENTITY(0,1) NOT NULL,
    [name] NVARCHAR(100),
    CONSTRAINT [PK_menu] PRIMARY KEY ([id])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "Sys_Roll_Menu"                                              */
/* ---------------------------------------------------------------------- */

CREATE TABLE [Sys_Roll_Menu] (
    [id_roll] INTEGER,
    [id_menu] INTEGER
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "Car"                                                        */
/* ---------------------------------------------------------------------- */

CREATE TABLE [Car] (
    [id] INTEGER IDENTITY(0,1) NOT NULL,
    [type] NVARCHAR(100),
    [NSX] NVARCHAR(100),
    [Image] NVARCHAR(100),
    [Detail] NVARCHAR(100),
    [Tieu_Hao_Nhien_Lieu] NVARCHAR(40),
    [Nhien_Lieu_Trong_Binh] NVARCHAR(40),
    [status] INTEGER,
    CONSTRAINT [PK_Car] PRIMARY KEY ([id])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "Chi_Tieu"                                                   */
/* ---------------------------------------------------------------------- */

CREATE TABLE [Chi_Tieu] (
    [id] INTEGER IDENTITY(0,1) NOT NULL,
    [detail] NVARCHAR(100),
    [total] NVARCHAR(100),
    [id_car] INTEGER,
    CONSTRAINT [PK_Chi_Tieu] PRIMARY KEY ([id])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "Mail"                                                       */
/* ---------------------------------------------------------------------- */

CREATE TABLE [Mail] (
    [id] INTEGER IDENTITY(0,1) NOT NULL,
    [to] NVARCHAR(100),
    [detail] NVARCHAR(100),
    [status] INTEGER,
    CONSTRAINT [PK_Mail] PRIMARY KEY ([id])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "Employee"                                                   */
/* ---------------------------------------------------------------------- */

CREATE TABLE [Employee] (
    [id] INTEGER IDENTITY(0,1) NOT NULL,
    [Name] NVARCHAR(100),
    [date] NVARCHAR(100),
    [user] NVARCHAR(100),
    [passwor] NVARCHAR(100),
    [email] NVARCHAR(100),
    [address] NVARCHAR(100),
    [phone] NVARCHAR(20),
    [id_roll] INTEGER,
    CONSTRAINT [PK_Employee] PRIMARY KEY ([id])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "Car_Thue"                                                   */
/* ---------------------------------------------------------------------- */

CREATE TABLE [Car_Thue] (
    [id] INTEGER IDENTITY(0,1) NOT NULL,
    [id_emp] INTEGER,
    [id_car] INTEGER,
    [date_xuat_phat] NVARCHAR(100),
    [date_tra_xe] NVARCHAR(100),
    [quang_duong] NVARCHAR(11),
    [status] INTEGER,
    CONSTRAINT [PK_Car_Thue] PRIMARY KEY ([id])
)
GO


/* ---------------------------------------------------------------------- */
/* Add table "Lich_driver"                                                */
/* ---------------------------------------------------------------------- */

CREATE TABLE [Lich_driver] (
    [id] INTEGER IDENTITY(0,1) NOT NULL,
    [id_car_thue] INTEGER,
    [id_driver] INTEGER,
    CONSTRAINT [PK_Lich_driver] PRIMARY KEY ([id])
)
GO


/* ---------------------------------------------------------------------- */
/* Foreign key constraints                                                */
/* ---------------------------------------------------------------------- */

ALTER TABLE [Employee] ADD CONSTRAINT [Roll_Employee] 
    FOREIGN KEY ([id_roll]) REFERENCES [Roll] ([id])
GO


ALTER TABLE [Sys_Roll_Menu] ADD CONSTRAINT [Roll_Sys_Roll_Menu] 
    FOREIGN KEY ([id_roll]) REFERENCES [Roll] ([id])
GO


ALTER TABLE [Sys_Roll_Menu] ADD CONSTRAINT [menu_Sys_Roll_Menu] 
    FOREIGN KEY ([id_menu]) REFERENCES [menu] ([id])
GO


ALTER TABLE [Car_Thue] ADD CONSTRAINT [Car_Car_Thue] 
    FOREIGN KEY ([id_car]) REFERENCES [Car] ([id])
GO


ALTER TABLE [Car_Thue] ADD CONSTRAINT [Employee_Car_Thue] 
    FOREIGN KEY ([id_emp]) REFERENCES [Employee] ([id])
GO


ALTER TABLE [Lich_driver] ADD CONSTRAINT [Employee_Lich_driver] 
    FOREIGN KEY ([id_driver]) REFERENCES [Employee] ([id])
GO


ALTER TABLE [Lich_driver] ADD CONSTRAINT [Car_Thue_Lich_driver] 
    FOREIGN KEY ([id_car_thue]) REFERENCES [Car_Thue] ([id])
GO


ALTER TABLE [Chi_Tieu] ADD CONSTRAINT [Car_Chi_Tieu] 
    FOREIGN KEY ([id_car]) REFERENCES [Car] ([id])
GO

